package com.atguigu.factory.improve;

import com.atguigu.factory.Pizza;

import java.util.Scanner;

/**
 * @ClassName OrderPizza
 * @Description TODO
 * @Author HongJian-Yang
 * @Date 2020/6/17 0:06
 * @Version 1.0
 */
public class OrderPizza {
    private SimpleFactory simpleFactory;

    public void setSimpleFactory(SimpleFactory simpleFactory) {

        this.simpleFactory = simpleFactory;
        do {
            Pizza pizza = simpleFactory.createPizza(getType());
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("订购失败,请重试");
            }
        } while (true);
    }

    public String getType() {
        Scanner scanner = new Scanner(System.in);
        return scanner.next();
    }
}
